package com.iyjhsoc.game.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iyjhsoc.game.dao.GameKillInfoDAO;
import com.iyjhsoc.game.domain.VO.GameKillInfoVO;
import com.iyjhsoc.game.domain.dto.GameKillInfoDTO;
import com.iyjhsoc.game.domain.dto.OneKillDTO;
import com.iyjhsoc.game.domain.entity.GameKillInfoDO;
import com.iyjhsoc.game.domain.response.Response;
import com.iyjhsoc.game.service.GameKillInfoService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GameKillInfoServiceImpl extends ServiceImpl<GameKillInfoDAO, GameKillInfoDO> implements GameKillInfoService {
    @Autowired
    GameKillInfoDAO gameKillInfoDAO;

    @Override
    public Response getOneKill(GameKillInfoVO vo) {
        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
        List<GameKillInfoDTO> gameKillInfoDTOS = gameKillInfoDAO.selectGameOneKill(vo);
        return Response.SUCCESS(new PageInfo<>(gameKillInfoDTOS));
    }

    @Override
    public Response getPositionRare(GameKillInfoVO vo) {

        List<GameKillInfoDTO> gameKillInfoDTOS = gameKillInfoDAO.selectGameOneKill(vo);
        Double team = 0.0;
        Double top = 0.0;
        Double jug = 0.0;
        Double mid = 0.0;
        Double bom = 0.0;
        Double ass = 0.0;
        Double victory = 0.0;
        for(GameKillInfoDTO gameKillInfoDTO: gameKillInfoDTOS){
            if(gameKillInfoDTO.getTeamId().equals(vo.getTeamId())){
                if(gameKillInfoDTO.getVictoryTeamId().equals(vo.getTeamId())){
                    victory++;
                }
                team++;
                if("1".equals(gameKillInfoDTO.getKillAddress())){
                    top++;
                } else if("2".equals(gameKillInfoDTO.getKillAddress())){
                    jug++;
                } else if("3".equals(gameKillInfoDTO.getKillAddress())){
                    mid++;
                } else if("4".equals(gameKillInfoDTO.getKillAddress())){
                    bom++;
                } else  if("5".equals(gameKillInfoDTO.getKillAddress())){
                    ass++;
                }
            }

        }
        OneKillDTO oneKillDTO = new OneKillDTO();
        oneKillDTO.setTeam(team/gameKillInfoDTOS.size());
        oneKillDTO.setTop(top/team);
        oneKillDTO.setJug(jug/team);
        oneKillDTO.setMid(mid/team);
        oneKillDTO.setBom(bom/team);
        oneKillDTO.setAss(ass/team);
        oneKillDTO.setVictory(victory/team);
        return Response.SUCCESS(oneKillDTO);
    }

    @Override
    public Response giveOneKillRare(GameKillInfoVO vo) {
        List<GameKillInfoDTO> gameKillInfoDTOS = gameKillInfoDAO.selectGameOneKill(vo);
        Double team = 0.0;
        Double top = 0.0;
        Double jug = 0.0;
        Double mid = 0.0;
        Double bom = 0.0;
        Double ass = 0.0;
        Double victory = 0.0;
        for(GameKillInfoDTO gameKillInfoDTO: gameKillInfoDTOS){
            if(!gameKillInfoDTO.getTeamId().equals(vo.getTeamId())){
                if(vo.getTeamId().equals(gameKillInfoDTO.getVictoryTeamId())){
                    victory++;
                }
                team++;
                if("1".equals(gameKillInfoDTO.getDeathAddress())){
                    top++;
                } else if("2".equals(gameKillInfoDTO.getDeathAddress())){
                    jug++;
                } else if("3".equals(gameKillInfoDTO.getDeathAddress())){
                    mid++;
                } else if("4".equals(gameKillInfoDTO.getDeathAddress())){
                    bom++;
                } else  if("5".equals(gameKillInfoDTO.getDeathAddress())){
                    ass++;
                }
            }

        }
        OneKillDTO oneKillDTO = new OneKillDTO();
        oneKillDTO.setTeam(team/gameKillInfoDTOS.size());
        oneKillDTO.setTop(top/team);
        oneKillDTO.setJug(jug/team);
        oneKillDTO.setMid(mid/team);
        oneKillDTO.setBom(bom/team);
        oneKillDTO.setAss(ass/team);
        oneKillDTO.setVictory(victory/team);
        return Response.SUCCESS(oneKillDTO);
    }

    @Override
    public Response getKillData(GameKillInfoVO vo) {
//        gameKillInfoDAO.

        return null;
    }
}
